<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Story
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
?>

<?php if ($this->paginator->getTotalItemCount()): ?>

  <?php if( $this->tag || $this->keyword):?>
    <div class="stories_result_filter_details">
      <?php echo $this->translate('Showing stories posted'); ?>
      <?php if ($this->tag): ?>
        <?php echo $this->translate('using tag #%s', $this->htmlLink(
          array('route'=>'story_manage','tag'=>$this->tag),
          $this->tagObject ? $this->tagObject->text : $this->tag
        ));?>
      <?php endif; ?>
      <?php if ($this->keyword): ?>
        <?php echo $this->translate('with keyword %s', $this->htmlLink(
          $this->url(array('keyword'=>$this->keyword), 'story_manage', true),
          $this->keyword
        ));?>
      <?php endif; ?>   
      <?php echo $this->htmlLink(array('route'=>'story_manage'), $this->translate('(x)'));?>
    </div>
  <?php endif; ?>

    <ul class='stories_rows'>
      <?php foreach ($this->paginator as $story): ?>
        <li>
          <?php if ($this->showphoto): ?>
            <div class="story_photo">
              <?php echo $this->htmlLink($story->getHref(), $this->itemPhoto($story, 'thumb.normal'));?>
            </div>
          <?php endif; ?>
          <div class='story_options'>
			<?php if($story->published && $story->category_id==Story_Model_Category::NOVEL && $story->allowChapters() && $story->canChange($this->viewer())): 
				$title_chapter = "Chapters";
				$add_chapter = "Add Chapter";				
			?>
            <a href='<?php echo $this->url(array('action' => 'index', 'story_id' => $story->story_id), 'story_chapter', true) ?>' class='buttonlink icon_story_manage_chapters'><?php echo $this->translate($title_chapter);?></a>
            <a href='<?php echo $this->url(array('action'=>'create', 'story_id' => $story->story_id), 'story_chapter', true) ?>' class='buttonlink icon_story_add_chapter smoothbox'><?php echo $this->translate($add_chapter);?></a>
			<?php endif; ?>
      <?php if($story->category_id==Story_Model_Category::STORY_THREAD && $story->allowChapters()): 
        $title_chapter = "Chapters";
        $add_chapter = "Add Chapter";       
      ?>
            <?php if($story->owner_id==$this->user_id){ ?>
            <a href='<?php echo $this->url(array('action' => 'index', 'story_id' => $story->story_id), 'story_chapter', true) ?>' class='buttonlink icon_story_edit'><?php echo $this->translate('Edit Story');?></a>
             <?php } ?>
      <?php endif; ?>
			<?php if($story->category_id==Story_Model_Category::NOVEL && $story->published == 0 && $story->canChange($this->viewer())): ?>
            <?php if($story->category_id==Story_Model_Category::NOVEL){ ?>
            <a href='<?php echo $this->url(array('action'=>'create', 'story_id' => $story->story_id), 'story_general', true) ?>' class='buttonlink icon_story_edit'><?php echo $this->translate('Edit Story');?></a>
             <?php } ?>
			<?php endif; ?>
      <?php if($story->category_id==Story_Model_Category::STORY_THREAD
       && (($story->owner_id==$this->user_id && ($story->invite_request==1||$story->invite_request==0))||($story->owner_id!=$this->user_id && ($story->invite_request==2||$story->invite_request==0)))){ ?>
      <a href='<?php echo $this->url(array('action'=>'create', 'story_id' => $story->story_id), 'story_general', true) ?>' class='buttonlink icon_story_add_chapter'><?php echo $this->translate('Add Chapter');?></a>
       <?php } else if($story->category_id==Story_Model_Category::STORY_THREAD) { ?>
       <a class="buttonlink icon_story_add_chapter"><?php echo $this->translate('Add Locked');?></a>
       <?php } ?>
            <?php if( $this->allowed_upload && $story->canAddPhotos()): ?>
              <?php echo $this->htmlLink(array(
                  'route' => 'story_extended',
                  'controller' => 'photo',
                  'action' => 'upload',
                  'subject' => $story->getGuid(),
                ), $this->translate('Add Photos'), array(
                  'class' => 'buttonlink icon_story_photo_new'
              )) ?>
            <?php endif; ?>
            <?php if($story->owner_id==$this->user_id){ ?>
            <a href='<?php echo $this->url(array('action'=>'delete', 'story_id' => $story->story_id), 'story_specific', true) ?>' class='buttonlink icon_story_delete'><?php echo $this->translate('Delete Story');?></a>
             <?php } ?>
            <?php if( !$story->published ): ?>
            	<?php if ($this->approval): ?>
            	  <a href="javascript:void(0)" onclick="alert('<?php echo $this->translate('Administrator will manually review and publish this story.');?>'); return false;" class='buttonlink icon_story_publish'><?php echo $this->translate('Status: Draft'); ?></a>
            	<?php else: ?>
              <?php if($story->owner_id==$this->user_id){ ?>
            	  <a href='<?php echo $this->url(array('story_id' => $story->story_id), 'story_publish', true) ?>' class='buttonlink icon_story_publish'><?php echo $this->translate('Publish Story');?></a>
                <?php } ?>
            	<?php endif; ?>
            <?php endif; ?>
          </div>
          <div class="story_content">
            <div class="story_title">
              <?php echo $this->partial('index/_title.tpl', 'story', array('story' => $story))?> (<?php echo $story->getPublishStatus(); ?>)
            </div>
            <?php if ($this->showmeta): ?>
              <div class="story_meta">
                <?php echo $this->partial('index/_meta.tpl', 'story', array('story' => $story))?>
              </div>  
            <?php endif; ?>
            <?php if ($this->showdescription && $story->getDescription()): ?>
              <div class="story_description">
                <?php echo $this->viewMore($story->getDescription()); ?>
              </div>
            <?php endif; ?>
          </div>
        </li>
      <?php endforeach; ?>  
    </ul>
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
<?php elseif ( $this->tag || $this->keyword || $this->category): ?>       
  <div class="tip">
    <span>
      <?php echo $this->translate('You do not have any story that match your search criteria.');?>
    </span>
  </div>
<?php else: ?>    
  <div class="tip">
    <span>
      <?php echo $this->translate('You do not have any stories.');?>
        <?php if ($this->can_create): ?>
          <?php echo $this->translate('Get started by <a href=\'%1$s\'>posting</a> a new story.', $this->url(array(), 'story_create', true));?>
        <?php endif; ?>        
    </span>  
  </div>
<?php endif; ?>
